home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / mem-break.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  3KB  |  103 lines

  1. /* Simulate breakpoints by patching locations in the target system.
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "param.h"
  22.  
  23. #ifdef BREAKPOINT
  24. /* This file is only useful if BREAKPOINT is set.  If not, we punt.  */
  25.  
  26. #include <stdio.h>
  27. #include "breakpoint.h"
  28. #include "inferior.h"
  29. #include "target.h"
  30.  
  31. /* This is the sequence of bytes we insert for a breakpoint.  On some
  32.    machines, breakpoints are handled by the target environment and we
  33.    don't have to worry about them here.  */
  34.  
  35. static char break_insn[] = BREAKPOINT;
  36.  
  37. /* This is only to check that BREAKPOINT fits in BREAKPOINT_MAX bytes.  */
  38.  
  39. static char check_break_insn_size[BREAKPOINT_MAX] = BREAKPOINT;
  40.  
  41. /* Insert a breakpoint on machines that don't have any better breakpoint
  42.    support.  We read the contents of the target location and stash it,
  43.    then overwrite it with a breakpoint instruction.  ADDR is the target
  44.    location in the target machine.  CONTENTS_CACHE is a pointer to 
  45.    memory allocated for saving the target contents.  It is guaranteed
  46.    by the caller to be long enough to save sizeof BREAKPOINT bytes.
  47.    FIXME: This size is target_arch dependent and should be available in
  48.    the target_arch transfer vector, if we ever have one...  */
  49.  
  50. int
  51. memory_insert_breakpoint (addr, contents_cache)
  52.      CORE_ADDR addr;
  53.      char *contents_cache;
  54. {
  55.   int val;
  56.  
  57.   val = target_read_memory (addr, contents_cache, sizeof break_insn);
  58.  
  59.   if (val == 0)
  60.     val = target_write_memory (addr, break_insn, sizeof break_insn);
  61.  
  62.   return val;
  63. }
  64.  
  65.  
  66. int
  67. memory_remove_breakpoint (addr, contents_cache)
  68.      CORE_ADDR addr;
  69.      char *contents_cache;
  70. {
  71.   return target_write_memory (addr, contents_cache, sizeof break_insn);
  72. }
  73.  
  74.  
  75. int memory_breakpoint_size = sizeof (break_insn);
  76.  
  77.  
  78. #else  /* BREAKPOINT */
  79.  
  80. char nogo[] = "Breakpoints not implemented for this target.";
  81.  
  82. int
  83. memory_insert_breakpoint (addr, contents_cache)
  84.      CORE_ADDR addr;
  85.      char *contents_cache;
  86. {
  87.   error (nogo);
  88.   return 0;    /* lint */
  89. }
  90.  
  91. int
  92. memory_remove_breakpoint (addr, contents_cache)
  93.      CORE_ADDR addr;
  94.      char *contents_cache;
  95. {
  96.   error (nogo);
  97.   return 0;    /* lint */
  98. }
  99.  
  100. int memory_breakpoint_size = -1;
  101.  
  102. #endif /* BREAKPOINT */
  103.